<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
loadcache('plugin');
$config=$_G['cache']['plugin']['yy_pay'];
$pay_pro=yy_pay_get_setting();
if(submitcheck('submit')){
	$groups=$_GET['groupid'];
	$maxs=$_GET['max'];
	$bls=$_GET['bl'];
	$pay_pros=array();
	for($i=0;$i<count($groups);$i++){
		if(intval($groups[$i])){
			$pay_pros[$groups[$i]]['max']=intval($maxs[$i])?intval($maxs[$i]):$config['p_max'];
			$pay_pros[$groups[$i]]['bl']=intval($bls[$i])?intval($bls[$i]):$config['p_bl'];
		}
	}
	if($pay_pro['time']<$_G['timestamp']&&$pay_pro['time'])
		$pay_pros['time']=$pay_pro['time'];
	else
		$pay_pros['time']=$_G['timestamp'];
	require_once libfile('function/cache');
	writetocache('yy_pay_pro', getcachevars(array('pay_pro' =>$pay_pros)));
	cpmsg(plang('var34'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=yy_pay&pmod=yy_pro', 'succeed');
}
$groupselect = array();
$query=DB::query("SELECT * FROM ".DB::table('common_usergroup')." WHERE groupid in(".dimplode(unserialize($config['p_allow'])).")");
while($group = DB::fetch($query)) {
	$group['type'] = $group['type'] == 'special' && $group['radminid'] ? 'specialadmin' : $group['type'];
	$groupselect[$group['type']][] = array('groupid'=>$group['groupid'],'grouptitle'=>$group['grouptitle']);
}
showformheader('plugins&operation=config&do='.$pluginid.'&identifier=yy_pay&pmod=yy_pro');
foreach($groupselect as $k=>$gs){
	showtableheader($lang['usergroups_'.$k.''], '');
	showsubtitle(array('',plang('var35'),plang('var36').'('.$_G['setting']['extcredits'][$config['p_credit']]['title'].')', plang('var37')));
	foreach($gs as $g){
		$gjsd['max']=$config['p_max'];
		$gjsd['bl']=$config['p_bl'];
		if($pay_pro[$g['groupid']])
			$gjsd=$pay_pro[$g['groupid']];
		showtablerow('', array('', '','', ''), array("<input type=\"hidden\" name=\"groupid[]\" value=\"$g[groupid]\">",$g['grouptitle'],'<input type="number" name="max[]" value="'.$gjsd['max'].'" />','<input type="number" name="bl[]" value="'.$gjsd['bl'].'" />'));
	}
}
showtablefooter();
showsubmit('submit', 'submit');
showformfooter();

function yy_pay_get_setting(){
	global $_G;
	if($_G['setting']['version']=='X2.5')
		$dircache='sysdata';
	else
		$dircache='cache';
	if(file_exists(DISCUZ_ROOT.'./data/'.$dircache.'/cache_yy_pay_pro.php'))
		require_once DISCUZ_ROOT.'./data/'.$dircache.'/cache_yy_pay_pro.php';
	return $pay_pro;
}
function plang($str) {
	return lang('plugin/yy_pay', $str);
}
?>